<%--
  Created by IntelliJ IDEA.
  User: zhao
  Date: 17-1-24
  Time: 上午10:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑文章</title>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/resource/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/resource/ueditor/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/resource/ueditor/lang/zh-cn/zh-cn.js"></script>

    <script type="text/javascript" src="${pageContext.request.contextPath}/resource/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resource/easyui/jquery.easyui.min.js"></script>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/easyui/themes/default/easyui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/easyui/themes/icon.css">

    <script type="text/javascript" src="${pageContext.request.contextPath}/resource/js/common.js"></script>

    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/resource/jquery.form.min.js"></script>
</head>
<body>

<div>

    <script type="text/javascript">


        //表单重置
        function formReset() {

        }

        $(function () {
            //选择图片后上传
            $(".file-upload-form [name='file']").bind('change', function () {
                var formData = new FormData($('.file-upload-form')[0]);
                $.ajax({
                    url:'/admin/file/fileUpload.do',
                    type:'POST',
                    //将formData对象作为参数进行上传
                    data:formData,
                    contentType: false,
                    processData: false,
                    success:function (data) {
                        if(data.status=='success'){
                            //文件上传成功后的处理
                            $('.create-news-img').attr('src',data.content);
                            $('input[name="thumbnailPath"]').val(data.content);
                        }
                    }
                })
            });
            $('.select-photo').bind('click',function () {
                $(".file-upload-form [name='file']").click();
            });
            $('.create-news-submit').bind('click',function () {
                if (UE.getEditor('editor').hasContents()){
                    var content = UE.getEditor('editor').getContent();
                    //有内容 提交
                    $('#newsContent').val(content);
                    var date = $('#newsDate').datebox('getValue');
                    $('#newsDate').val(date);
                    $('#form').submit();
                    var formData = new FormData($('.create-news-form')[0]);
                    $.ajax({
                        url:'/admin/news/createNews.do',
                        type:'POST',
                        //将formData对象作为参数进行上传
                        data:formData,
                        contentType: false,
                        processData: false,
                        success:function (data) {
                            if (data.status == 'success') {
                                $.messager.alert('成功', '模块添加成功');
                            }
                            else {
                                $.messager.alert('失败', '添加文章失败');
                            }
                        },
                        error:function() {
                            $.messager.alert('失败', '添加文章失败');
                        }
                    })
                }else{
                    //无内容
                    $.messager.alert('警告','请输入内容');

                }
            })

        })
    </script>
    <form class="create-news-form" id="form" enctype="multipart/form-data" method="post" onsubmit="return false;" >
        <table width="100%">
            <tr style="width: 100%;">
                <td style="width: 50px;">
                    标题
                </td>
                <td >
                    <input class="easyui-textbox easyui-validatebox" name="title" data-options="required:true,invalidMessage:'标题长度1到60个字符之间'" style="width:100%;" >
                </td>
            </tr>
            <tr>
                <td>
                    简介
                </td>
                <td>
                    <input class="easyui-textbox" name="intrduce"  style="width:100%">
                </td>
            </tr>
            <tr>
                <td>
                    作者
                </td>
                <td>
                    <input class="easyui-textbox" name="author"  style="width:100%">
                </td>
            </tr>
            <tr>
                <td>模块</td>
                <td>
                    <select id="module" name="module.id" style="width:200px;"></select>
                </td>
            </tr>
            <tr>
                <td>缩略图</td>
                <td>
                    <input name="thumbnailPath" type="hidden"/>
                    <a class="select-photo" class="easyui-linkbutton"  >选择图片</a>
                </td>

            </tr>
            <tr>
                <td></td>
                <%--缩略图展示--%>
                <td>
                    <img class="create-news-img" style="max-height: 100px;max-width: 100px"/>
                </td>
            </tr>
        </table>
        <input id="newsContent" name="content" type="hidden">
        <div style="width:100%;">
        </div>
        <div id="editor" type="text/plain" style="width:100%;height:250px;"></div>

        <div style="text-align: right">
            <a class="easyui-linkbutton" data-options="iconCls:'icon-reload'" onclick="formReset()">重置</a>
            <span class="easyui-linkbutton create-news-submit" data-options="iconCls:'icon-save'" >保存</span>
            选择发布时间:<input id="newsDate" name="date">
        </div>
        <script type="text/javascript">
            $('#module').combobox({
                url:'/module/moduleJson.do',
                valueField:'id',
                textField:'name'
            });
            $('#fb').filebox({
                buttonText: '选择缩略图',
                buttonAlign: 'left'
            });
            $('#newsDate').datebox({
                requested:true
            })
            $('#newsDate').datebox('setValue',new Date().toString());
        </script>
    </form>
    <%--缩略图上传表单--%>
    <form class="file-upload-form" enctype="multipart/form-data">
        <input  name="file" type="file" style="visibility: hidden">
    </form>
</div>
<script type="text/javascript">
    UE.delEditor('editor');
    var ue = UE.getEditor('editor');

</script>

</body>
</html>
